<template>
  <div class="info" v-loading="loading">
    <div class="card_con mb15">
      <el-row>
        <el-col :span="5" class="pr40">
          <div class="fz13 mb10">商家类别：</div>
          <el-select clearable v-model="mch_type" placeholder="请选择">
            <el-option
              v-for="item in mch_typeArr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="5" class="pr40">
          <div class="fz13 mb10">关键字：</div>
          <el-input
            v-model="storeName"
            placeholder="请输入店铺名、店铺id"
            clearable
          ></el-input>
        </el-col>
        <el-col :span="9" class="pr40">
          <div class="fz13 mb15">时间：</div>
          <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-col>
        <el-col :span="5">
          <div class="fz13 mb15">&nbsp;</div>
          <el-button type="primary" @click="handleQuery">查询</el-button>
        </el-col>
      </el-row>
    </div>
    <div class="card_con">
      <el-table
        border
        :data="tableData"
        :header-cell-style="{
          'text-align': 'center',
        }"
        :cell-style="{ 'text-align': 'center' }"
        style="width: 100%"
        highlight-current-row
      >
        <el-table-column type="selection" min-width="5%"> </el-table-column>
        <el-table-column prop="id" label="id" min-width="10%">
        </el-table-column>
        <el-table-column prop="name" label="店铺名" min-width="20%">
        </el-table-column>
        <el-table-column label="logo" min-width="10%">
          <template slot-scope="scope">
            <div class="slt">
              <el-popover placement="right" width="200" trigger="hover">
                <img class="tbImg1" :src="scope.row.logo.src" alt="" />
                <img
                  class="tbImg"
                  slot="reference"
                  :src="scope.row.logo.src"
                  alt=""
                />
              </el-popover>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="star" label="星级" min-width="10%">
        </el-table-column>
        <el-table-column prop="cate_text" label="分类" min-width="10%">
        </el-table-column>
        <el-table-column prop="tel" label="服务电话" min-width="10%">
        </el-table-column>
        <el-table-column prop="location" label="地址" min-width="10%">
        </el-table-column>
        <el-table-column prop="status" label="状态" min-width="15%">
          <template slot-scope="scope">
            <el-switch
              @change="changeSwitch(scope.row)"
              class="tablescope"
              v-model="scope.row.status"
              active-text="下架"
              inactive-text="上架"
              :active-value="1"
              :inactive-value="2"
              inactive-color=""
            >
            </el-switch>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="status" label="状态" min-width="10%">
        </el-table-column> -->
        <el-table-column prop="mch_type_text" label="类别" min-width="10%">
        </el-table-column>
        <el-table-column prop="status" label="营业时间" min-width="20%">
          <template slot-scope="scope">
            <div>{{ scope.row.busy_start }} - {{ scope.row.busy_end }}</div>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="province" label="地区" min-width="15%">
        </el-table-column> -->
        <el-table-column label="操作" min-width="30%">
          <template slot-scope="scope">
            <div class="caozuo">
              <div class="handleEdit hand_cs" @click="handleEdit(scope.row)">
                修改
              </div>
              <div
                class="handleExamine hand_cs"
                @click="handleDetail(scope.row)"
              >
                详情
              </div>
              <div
                class="handleDelete orange hand_cs"
                @click="handleJiesuan(scope.row)"
              >
                结算规则
              </div>
              <div
                class="handleDelete hand_cs"
                @click="handleDelete(scope.row)"
              >
                删除
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <Pagination :page="page" @onCurrentChange="handleCurrentChange" />
      </div>
      <el-dialog
        class="detailDialog"
        title="详情"
        :visible.sync="detailDialog"
        width="70%"
      >
        <DetailDialog v-if="detailDialog" :rowId="rowId"></DetailDialog>
      </el-dialog>
      <!-- 上架下架开关 -->
      <el-dialog
        title="上下架备注"
        :visible.sync="up_down_dialog"
        :close-on-click-modal="false"
        @close="remarkClose"
        width="500px"
      >
        <div class="beizhu">
          <div class="bz">
            <el-input v-model="remarks" placeholder="请输入备注"></el-input>
          </div>
          <div class="btn">
            <el-button type="primary" @click="handleRemark">提交</el-button>
          </div>
        </div>
      </el-dialog>
      <!-- 修改店铺 -->
      <el-dialog
        class="editDialog"
        title="编辑"
        :visible.sync="editDialog"
        width="70%"
        :close-on-click-modal="false"
      >
        <EditDailog
          v-if="editDialog"
          @handleClose="handleClose"
          :rowData="rowData"
        ></EditDailog>
      </el-dialog>
      <!-- 结算规则 -->
      <el-dialog
        class="editDialog"
        title="结算规则"
        :visible.sync="settleDialog"
        width="70%"
        :close-on-click-modal="false"
      >
        <SettleDialog v-if="settleDialog" :storeId="rowId"></SettleDialog>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import SettleDialog from "./settle_Dialog.vue";
import EditDailog from "./edit_shop_list_dialog.vue";
import Pagination from "@/components/Pagination.vue";
import DetailDialog from "./shop_list_dialog.vue";
import { store_list, storeUpDown } from "@/api/merchant";
export default {
  components: { Pagination, DetailDialog, EditDailog, SettleDialog },
  data() {
    return {
      loading: true,
      time: "",
      storeName: "",
      mch_typeArr: [
        { id: 1, name: "I类商家" },
        { id: 2, name: "II类商家商家" },
      ],
      mch_type: "",
      page: {
        total: 0,
        pageNum: 1, // 当前页数
        pageSize: 10, // 每页的条数
      },
      tableData: [],
      detailDialog: false, //详情弹窗
      editDialog: false, //修改弹窗
      rowId: "",
      up_down_dialog: false,
      settleDialog: false, //结算规则弹窗
      remarks: "", //开关备注
      remarks_state: "", //开关参数
      rowData: {},
    };
  },
  methods: {
    async store_list() {
      const { data, err } = await store_list({
        page: this.page.pageNum,
        mch_type: this.mch_type,
        key: this.storeName,
      });
      if (err === 0) {
        this.loading = false;
        this.tableData = data.data;
        this.page.pageSize = data.per_page;
        this.page.total = data.total;
      }
    },
    async storeUpDown() {
      const { err } = await storeUpDown({
        remark: this.remarks,
        id: this.rowId,
        type: this.remarks_state,
      });
      if (err === 0) {
        this.up_down_dialog = false;
        this.remarks = "";
        this.$message({
          showClose: true,
          message: "操作成功",
          type: "success",
        });
        if (this.remarks_state === "3") {
          this.store_list();
        }
      }
    },
    //开关编辑
    changeSwitch(row) {
      //0上架 1   1下架 2
      this.up_down_dialog = true;
      this.rowId = row.id;
      this.remarks_state = row.status;
    },
    //开关弹窗关闭
    remarkClose() {
      this.up_down_dialog = false;
      this.remarks = "";
      this.store_list();
    },
    //开关备注提交
    handleRemark() {
      if (this.remarks === "") {
        this.$message({
          showClose: true,
          message: "请输入备注",
          type: "warning",
        });
      } else {
        this.up_down_dialog = false;
        this.storeUpDown();
      }
    },
    //关闭编辑
    handleClose() {
      this.editDialog = false;
      this.store_list();
    },
    //查询
    handleQuery() {
      this.loading = true;
      this.page.pageNum = 1;
      this.store_list();
    },

    handleClick(tab) {
      console.log(tab);
    },
    //编辑
    handleEdit(row) {
      this.rowData = row;
      this.editDialog = true;
    },
    //详情
    handleDetail(row) {
      console.log(row);
      this.rowId = row.id;
      this.detailDialog = true;
    },
    //删除
    handleDelete(row) {
      this.$confirm("是否确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.remarks_state = "3";
          this.rowId = row.id;
          this.storeUpDown();
        })
        .catch(() => {
          console.log("1111111111111");
        });
    },
    // 当前页: ${val}
    handleCurrentChange(val) {
      this.page.pageNum = val;
      this.loading = true;
      this.store_list();
    },
    //结算规则
    handleJiesuan(row) {
      this.settleDialog = true;
      this.rowId = row.id;
    },
  },
  created() {
    this.store_list();
  },
};
</script>

<style lang="scss" scoped>
@import "@/style/index.scss";
.handleExamine {
  margin-left: 20px;
}
.info {
  .title {
    font-size: 16px;
    margin-bottom: 13px;
  }
}
.pagination {
  display: flex;
  justify-content: flex-end;
  padding-top: 10px;
}
.el-select {
  width: 100%;
}

.tb {
  background-color: #fff;
  padding: 20px;
  box-sizing: border-box;
}
.row {
  display: flex;
  border-radius: 2px;
  .l {
    padding: 8px 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #ccc;
    font-size: 13px;
    i {
      margin-right: 6px;
      font-size: 13px;
    }
    &:hover {
      cursor: pointer;
    }
  }
  .l:nth-child(3) {
    border-right: 0;
  }
}
.caozuo {
  display: flex;
  justify-content: center;
  .handleDelete {
    margin-left: 20px;
  }
}
.detailDialog,
.editDialog {
  /deep/.el-dialog {
    height: 82%;
    margin-top: 10vh !important;
    .el-dialog__body {
      height: 80%;
      overflow: auto;
    }
  }
}

.beizhu {
  padding: 0 20px 50px 20px;
  box-sizing: border-box;
  .bz {
    margin-bottom: 10px;
    margin-top: 20px;
  }
  .btn {
    margin-top: 20px;
    .el-button {
      width: 100%;
    }
  }
}
</style>
